define(["dzBaseView", "cMemberService", "cUtilCryptBase64", "scripts/vbkUtil", "scripts/vbridge", "scripts/cookie", "models/vStore", "models/vModel", "scripts/vModelFacade", "text!templates/orderPool.html", "text!templates/orderPoolList.html", "text!templates/orderPoolFanpaiList.html", "scripts/native"],
    function(cPageView, member, cUtilCryptBase64, vbkUtil, vbridge, ck, store, m, mFacade, orderPool, poolList, fanpaiList, native) {

        var getOrderListModel = m.GetRobRequireListModel.getInstance(),
            GetConversationUnreadInfoModel = m.GetConversationUnreadInfoModel.getInstance(),
            GetTotalUnreadcountModel = m.GetTotalUnreadcountModel.getInstance(),
            GetRobOrderVerifyCodeEnabledModel = m.GetRobOrderVerifyCodeEnabled.getInstance(),
            cookieUserInfor, //登录态用户信息cookie
            listedNum = 0,
            loadingNow = false,
            isAllDemand = false,
            nomoreListShow = false;

        var protocol = window.location.protocol.toLowerCase(); //当前协议
        var isIgnoreLogin = (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() === 'wechat' || Lizard.P('sourcefrom').toLowerCase() === 'sms')) ? true : false;

        return cPageView.extend({
            // pageid: '10320641802',
            // hpageid: '10320641802',

            events: {
                "click .rob_list_back": "backToOrigin",
                "click .j_call": "callUser",
                "click .j_ImChatList": "ImChatWakeUp",
                "click .j_imMessageList": "imMessageListEnter"
            },

            getImChatUrl: function() {
                var self = this,
                    imChatH5Url,
                    fatImChatUrl = "http://m.ctrip.fat27.qa.nt.ctripcorp.com/webapp/tours/csplatform/",
                    uatImChatUrl = "https://m.uat.qa.nt.ctripcorp.com/webapp/tours/csplatform/",
                    prodImChatUrl = "https://m.ctrip.com/webapp/tours/csplatform/";

                if (self.getEvnCode() == 0) {
                    imChatH5Url = fatImChatUrl;
                } else if (self.getEvnCode() == 2) {
                    imChatH5Url = uatImChatUrl;
                } else if (self.getEvnCode() == 3) {
                    imChatH5Url = prodImChatUrl;
                }

                return imChatH5Url;
            },

            imMessageListEnter: function() {
                var self = this,
                    imChatH5Url = self.getImChatUrl();

                if (!self.isInApp()) {
                    Lizard.jump(imChatH5Url + "imlist?from=" + encodeURIComponent(location.href), {
                        "loading": false
                    });

                } else {

                    if (self.isNewAppVersion) {
                        self.chatList();
                    } else {
                        Lizard.jump(imChatH5Url + "imlist?from=" + encodeURIComponent(location.href), {
                            "loading": false
                        });
                    }
                }
            },

            //IM接入 必传uid
            ImChatWakeUp: function(e) {
                var self = this,
                    evn = self.getEvnCode(),
                    uid = $(e.currentTarget).attr('data-uid');

                var buid = cUtilCryptBase64.Base64.encode(uid, false);

                self.myTracklog({
                    biz: 'imChatWakeUp'
                });

                var imChatH5Url = self.getImChatUrl();

                if (!self.isInApp()) {
                    Lizard.jump(imChatH5Url + "imDetail?buid=" + buid + "&from=" + encodeURIComponent(location.href), {
                        "loading": false
                    });

                } else {

                    if (self.isNewAppVersion) {
                        self.singleChat(uid);
                    } else {
                        Lizard.jump(imChatH5Url + "imDetail?buid=" + buid + "&from=" + encodeURIComponent(location.href), {
                            "loading": false
                        });
                    }
                }
            },

            singleChat: function(uid) {
                vbkUtil.setupWebViewJavascriptBridge(function(bridge) {
                    bridge.callHandler('CallIM', window.VBase64Tool._base64encode(JSON.stringify({
                        'method': 'chat',
                        'uid': uid
                    })), function(response) {
                        console.log(response);
                    });
                });
            },

            chatList: function(e) {
                vbkUtil.setupWebViewJavascriptBridge(function(bridge) {
                    bridge.callHandler('CallIM', window.VBase64Tool._base64encode(JSON.stringify({
                        'method': 'chatmessage'
                    })), function(response) {
                        console.log(response);
                    });
                });
            },

            callUser: function(e) {
                var self = this,
                    phoneNum = '021-22212666',
                    extNum = $(e.currentTarget).attr('data-phone'),
                    callMask = $('.j_callMask'),
                    $callCancel = $('.j_callCancel'),
                    $callOk = $('.j_callOk');


                e.stopPropagation();

                callMask.show();
                $callCancel.click(function() {
                    if (self.isInApp()) {
                        window['__bfi'].push(['_tracklog', 'cus_graboffer_dlt_app', "callout_yn=0"]);
                    } else {
                        window['__bfi'].push(['_tracklog', 'cus_graboffer_dlt_h5', "callout_yn=0"]);
                    }
                    callMask.hide();
                });

                $callOk.click(function() {

                    if (self.isInApp()) {
                        window['__bfi'].push(['_tracklog', 'cus_graboffer_dlt_app', "callout_yn=1"]);
                    } else {
                        window['__bfi'].push(['_tracklog', 'cus_graboffer_dlt_h5', "callout_yn=1"]);
                    }
                    $this = $(this);
                    var telNumber = phoneNum + ',' + extNum;
                    window.location = "tel:" + telNumber;

                });
            },

            backToOrigin: function() {
                var self = this,
                    from = Lizard.P('from'),
                    deviceInfoVersion = $('.rob_list_back').attr('deviceInfoVersion');

                if (deviceInfoVersion && !(deviceInfoVersion < "2.0.0")) {
                    native.closeWebView();
                } else {
                    location.href = from;
                }
                /**
                 if (location.origin.toLowerCase().indexOf("https") != -1) {
                    location.href = (location.origin.toLowerCase() + "/VBKH5/board");
                } else {
                    location.href = (location.origin.toLowerCase() + "/VBKH5/board").replace("http", "https");
                }
                 */

            },

            goToRobDetail: function(e) {
                var self = this,
                    from = Lizard.P('from');
                var currentUrl = window.location.href;
                var baseUrl = currentUrl.substr(0, currentUrl.indexOf("ist?") - 4);
                if (isIgnoreLogin) {
                    Lizard.jump(baseUrl + "RobDetail?fromPage=rob_list&requireDetailId=" + $(e.currentTarget).attr('data-detailID') + '&sourceFrom=' + Lizard.P('sourceFrom') + '&providerid=' + Lizard.P('providerid') + '&userid=' + Lizard.P('userid') + "&orderType=" + $(e.currentTarget).attr('data-detailType') + "&from=" + from, {
                        "loading": false
                    });
                } else {
                    Lizard.jump(baseUrl + "RobDetail?fromPage=rob_list&requireDetailId=" + $(e.currentTarget).attr('data-detailID') + "&orderType=" + $(e.currentTarget).attr('data-detailType') + "&from=" + from, {
                        "loading": false
                    });
                }

            },

            oldLogin: function() {
                var fromUrl = encodeURIComponent(location.href),
                    backUrl = encodeURIComponent(location.href); //我携登录页点击退回按钮的时候返回
                var host = window.location.host.toLowerCase();
                if (!member.isLogin()) {
                    if (host.indexOf('fat') >= 0 || host.indexOf('localhost') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('http://accounts.fat49.qa.nt.ctripcorp.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else if (host.indexOf('fws') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('http://accounts.fat49.qa.nt.ctripcorp.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else if (host.indexOf('uat.qa.nt.ctripcorp') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('https://accounts.uat.qa.nt.ctripcorp.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else if (host.indexOf('uat.ctripqa.com') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('https://accounts.uat.ctripqa.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else {
                        fromUrl = encodeURIComponent('https://m.ctrip.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('https://accounts.ctrip.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    }
                }
            },

            //调native方法设置cookie userInfo
            callNativeUser: function(callback) {
                var self = this;
                if (self.isInApp()) {
                    native.callNative({
                        method: 'callGetUserInfo',
                        callback: function(response) {
                            //H5页面要用到cookie中的userInfo
                            cookieUserInfor = window.VAppTool.isAndroidApp() ? response && cUtilCryptBase64.Base64.decode(response) : response && JSON.parse(cUtilCryptBase64.Base64.decode(response)).userInfo;
                            // ck.addCookie('userInfo', userInfo, 30);
                            // cookieUserInfor = ck.getCookie("userInfo");
                            callback(cookieUserInfor);
                        }
                    })
                }
            },

            initOnShow: function(cookieUserInfor) {
                var self = this,
                    ifInit = true,
                    $orderTab = $('.j_orderTab a'),
                    $tabQiangdan = $('.j_qiangdan'),
                    $tabFanpai = $('.j_fanpai'),
                    orderType = Lizard.P('orderType') ? Lizard.P('orderType') : 'GrabOrder',
                    tabOpen = false,
                    deviceInfo;


                cookieUserInfor = cookieUserInfor || JSON.parse(ck.getCookie("userInfo"));
                if (cookieUserInfor || cookieUserInfor != '') {
                    userInfo = cookieUserInfor;
                    ctripUid = userInfo.CtripUid;
                } else {
                    ctripUid = "";
                }
                if (ctripUid == '') {
                    self.myTracklog({
                        biz: 'userInfoCookie',
                        value: cookieUserInfor,
                        localStorage_userInfor: localStorage.getItem('userInfo')
                    });
                    if (!self.isInApp()) {
                        self.oldLogin();

                    } else {
                        if (self.isNewAppVersion) {
                            if (window.VAppTool.isIOSApp()) {
                                param = {
                                    'method': 'isShowVbk'
                                };
                            } else {
                                param = {
                                    'method': 'isShowVbkAndCanBack'
                                };
                            }
                            vbkUtil.setupWebViewJavascriptBridge(function(bridge) {
                                bridge.callHandler('callCtripLogin', window.VBase64Tool._base64encode(JSON.stringify(param)), function(response) {});
                            });

                        } else {
                            self.oldLogin();
                        }
                    }
                } else {
                    //获取IM（总）未读信息条数
                    mFacade.excute(self, GetTotalUnreadcountModel, function(json) {
                        var unreadCount = json.unreadCount,
                            value;

                        if (unreadCount > 0 && unreadCount < 100) {
                            value = unreadCount;
                        } else if (unreadCount == 0) {
                            value = '';
                        } else if (unreadCount > 100) {
                            value = '99+';
                        }
                        $('.j_imMessageList').text(value)

                    }, function(obj, e) {}, false, isIgnoreLogin);

                    $('.view_header').css('background', '#394054'); //头部背景色

                    if (self.getQueryString('from') == 'rob_detail') {
                        ifInit = false;
                    }

                    self.$el.find('.goto_rob_detail').not('.j_call,.j_ImChatList').off('click').click(function(e) {
                        e.stopPropagation();
                        self.goToRobDetail();
                    });

                    //记录一下原来页面已显示的抢单池的需求单数量
                    listedNum = self.$el.find('.goto_rob_detail').length
                    var pageSize = Math.ceil(listedNum / 5) * 5
                    // self.headFix();

                    //待抢单数据渲染
                    $tabQiangdan.click(function() {
                        self.$el.find('.list_container').empty();
                        self.renderList('GrabOrder', true, isAllDemand, 1, pageSize == 0 ? 5 : pageSize, ifInit);
                        $('.j_orderTab').find('a').removeClass('cur');
                        $(this).addClass('cur');
                    });

                    self.renderList(orderType, tabOpen, isAllDemand, 1, pageSize == 0 ? 5 : pageSize, ifInit);

                    //待翻牌数据渲染
                    $tabFanpai.click(function() {
                        self.$el.find('.list_container').empty();
                        self.renderFanpaiList('TurnOrder', true, isAllDemand, 1, pageSize == 0 ? 5 : pageSize, ifInit);
                        $('.j_orderTab').find('a').removeClass('cur');
                        $(this).addClass('cur');
                    });


                    //选择显示全部需求单
                    $('.grab_content').off('click').on('click', '.j_isAllDemand', function(e) {
                        var $this = $(this);
                        $this.find('label').toggleClass('cur');
                        if ($this.find('label').hasClass('cur')) {
                            isAllDemand = true;
                        } else {
                            isAllDemand = false;
                        }
                        self.renderList('GrabOrder', tabOpen, isAllDemand, 1, pageSize == 0 ? 5 : pageSize, ifInit);
                    });

                    //下拉刷新
                    $(window).scroll(function(e) {
                        if ($('.j_qiangdan').hasClass('cur')) {
                            orderType = 'GrabOrder';
                        } else {
                            orderType = 'TurnOrder';
                        }

                        e.stopPropagation();
                        if ($(window).scrollTop() + $(window).height() >= $(document).height()) {
                            listedNum = self.$el.find('.goto_rob_detail').length
                            if (listedNum % 5 != 0) {
                                if (loadingNow == false && nomoreListShow == false) {
                                    self.renderList(orderType, tabOpen, isAllDemand, 1, Math.ceil(listedNum / 5) * 5, true, true);
                                }
                            } else if (listedNum % 5 == 0) {
                                if (loadingNow == false && nomoreListShow == false) {
                                    self.renderList(orderType, tabOpen, isAllDemand, 1, (Math.ceil(listedNum / 5) + 1) * 5, true, true);
                                }
                            }
                        }
                    });

                    var resultObj = {
                        result: 0
                    };

                    self.gesture($('.list_container'), function(e) {

                        if ($(window).scrollTop() == 0) {
                            //在顶端时候下拉刷新
                            listedNum = self.$el.find('.goto_rob_detail').length
                            if (listedNum % 5 != 0) {
                                if (loadingNow == false) {
                                    self.renderList(orderType, tabOpen, isAllDemand, 1, Math.ceil(listedNum / 5) * 5, true, true, true);
                                }
                            } else if (listedNum % 5 == 0) {
                                if (loadingNow == false) {
                                    self.renderList(orderType, tabOpen, isAllDemand, 1, (Math.ceil(listedNum / 5) + 1) * 5, true, true, true);
                                }
                            }
                        }
                        //e.stopPropagation();
                        return false;
                    }, resultObj);
                    $(document).on('click', '.goto_rob_detail', function(e) {
                        //console.log(resultObj);
                        self.goToRobDetail(e);
                    });
                }
            },

            onCreate: function() {
                var self = this;
                self.$el.html(orderPool);
            },

            onShow: function() {
                var self = this,
                    ifInit = true,
                    $orderTab = $('.j_orderTab a'),
                    $tabQiangdan = $('.j_qiangdan'),
                    $tabFanpai = $('.j_fanpai'),
                    orderType = Lizard.P('orderType') ? Lizard.P('orderType') : 'GrabOrder',
                    tabOpen = false,
                    deviceInfo;

                $('.cm-page-title').text('需求单管理');

                if (orderType == 'GrabOrder') { //待抢单列表
                    self.pageid = 10320641802;
                    self.hpageid = 10320641802;
                } else {
                    self.pageid = 10320641803;
                    self.hpageid = 10320641803;
                }


                window.app.getDeviceInfoCallBack = function(data) {
                    var deviceInfo = JSON.parse(data);
                    //登录态获取
                    var userInfo,
                        deviceInfoVersion;

                    self.isNewAppVersion = deviceInfo.version < "2.0.0" ? false : true; //IM接入版本判断
                    $('.rob_list_back').attr('deviceInfoVersion', deviceInfo.version);
                    deviceInfoVersion = deviceInfo.version;
                    if (deviceInfoVersion && !(deviceInfoVersion < "2.0.0")) {
                        native.hideHeader();

                        var robListcallback = function(data) {
                            cookieUserInfor = JSON.parse(data);
                            // if (userInfo) {
                            self.initOnShow(cookieUserInfor);
                            // }
                        };
                        self.callNativeUser(robListcallback); //2.0.0版本 Cookie userInfo set

                    } else {
                        self.initOnShow();
                    }
                };
                if (self.isInApp()) {
                    window.VAppUtil.getDeviceInfo(); //获取APP版本

                } else {
                    self.initOnShow();
                }

            },

            gesture: function($el, downCallback, resultObj) {
                //返回角度
                var self = this;

                function GetSlideAngle(dx, dy) {
                    return Math.atan2(dy, dx) * 180 / Math.PI;
                }

                //根据起点和终点返回方向 1：向上，2：向下，3：向左，4：向右,0：未滑动
                function GetSlideDirection(startX, startY, endX, endY) {
                    var dy = startY - endY;
                    var dx = endX - startX;
                    var result = 0;

                    //如果滑动距离太短
                    if (Math.abs(dx) < 2 && Math.abs(dy) < 2) {
                        return result;
                    }

                    var angle = GetSlideAngle(dx, dy);
                    if (angle >= -45 && angle < 45) {
                        result = 4;
                    } else if (angle >= 45 && angle < 135) {
                        result = 1;
                    } else if (angle >= -135 && angle < -45) {
                        result = 2;
                    } else if ((angle >= 135 && angle <= 180) || (angle >= -180 && angle < -135)) {
                        result = 3;
                    }

                    return result;
                }

                //滑动处理
                var startX, startY;
                var isTouch = false;
                var isMoveing = false;
                $el.on('touchstart', function(ev) {
                    startX = ev.touches[0].pageX;
                    startY = ev.touches[0].pageY;
                    //resultObj.result=0;
                    //isTouch=true;
                }, false);
                $el.on('touchmove', function(ev) {
                    //
                    var endX, endY;
                    endX = ev.changedTouches[0].pageX;
                    endY = ev.changedTouches[0].pageY;
                    var direction = GetSlideDirection(startX, startY, endX, endY);
                    switch (direction) {
                        case 0:
                            resultObj.result = 0;
                            break;
                        case 1:
                            resultObj.result = 1;
                            //ev.stopPropagation();
                            break;
                        case 2:
                            resultObj.result = 2;
                            if ($.isFunction(downCallback)) {
                                downCallback(ev);
                            }
                            break;
                        case 3:
                            resultObj.result = 3;
                            break;
                        case 4:
                            resultObj.result = 4;
                            break;
                        default:
                    }
                }, false);
                $el.on('touchend', function(ev) {
                    //
                }, false);
            },
            getQueryString: function(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            },

            renderList: function(orderType, tabOpen, isAllDemand, pageIndex, pageSize, ifInit, ifPull, ifRefresh) {
                var self = this,
                    orderType;
                $('.j_isAllDemand').show();
                if (isAllDemand == true) {
                    $('.j_isAllDemand label').addClass('cur');
                } else {
                    $('.j_isAllDemand label').removeClass('cur');
                }
                localStorage.setItem('dingzhi_orderType', orderType);
                //首次加载时候才显示加载中。。。,详情页回退不显示loading图标
                if (ifInit) {
                    self.$el.find('.next_page_loading').show();
                }
                if (ifRefresh) {
                    self.$el.find('.pull_loading').show();
                }
                if (ifPull) {
                    loadingNow = true;
                }
                var orderListParam = {
                    pageIndex: pageIndex,
                    pageSize: pageSize,
                    orderType: orderType,
                    isAll: isAllDemand
                }

                if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() == 'wechat' || Lizard.P('sourcefrom').toLowerCase() == 'sms' || Lizard.P('sourcefrom').toLowerCase() == 'appPush')) {
                    if (Lizard.P('providerid') && Lizard.P('userid')) {
                        $.extend(orderListParam, {
                            platformProviderId: Lizard.P('providerid'),
                            platformUserId: Lizard.P('userid')
                        });
                    } else {
                        //需要強制登錄（微信和）
                    }

                }
                getOrderListModel.setParam(orderListParam);
                mFacade.excute(self, getOrderListModel, function(json) {
                    var oldListNum = self.$el.find('.goto_rob_detail').length,
                        listTpl;

                    if (!tabOpen) {
                        if (json.Data.Items && json.Data.Items.length > 0 && orderType == 'GrabOrder') {
                            // if (json.Data.Items && json.Data.Items.length > 0) {
                            listTpl = poolList;
                        } else {
                            listTpl = fanpaiList;
                            self.renderFanpaiList('TurnOrder', true, isAllDemand, 1, pageSize == 0 ? 5 : pageSize, ifInit);
                        }
                        tabOpen = true;
                    } else {
                        if (orderType == 'GrabOrder') {
                            listTpl = poolList;
                        } else {
                            listTpl = fanpaiList;
                            self.renderFanpaiList('TurnOrder', true, isAllDemand, 1, pageSize == 0 ? 5 : pageSize, ifInit);
                        }
                    }


                    self.$el.find('.list_container').html(_.template(listTpl)({
                        "data": json
                    }));

                    if (ifInit) {
                        self.$el.find('.next_page_loading').hide();
                    }
                    if (ifRefresh) {
                        self.$el.find('.pull_loading').hide();
                    }
                    if (ifPull) {
                        loadingNow = false;
                        listedNum = self.$el.find('.goto_rob_detail').length
                        if (listedNum % 5 != 0 || oldListNum == listedNum) {
                            //防止频繁刷新列表当列表已经拉到底部时设置1500ms的延时才能再度刷新
                            self.$el.find('.rob_list_nomore').show();
                            nomoreListShow = true;
                            setTimeout(function() {
                                self.$el.find('.rob_list_nomore').hide();
                                nomoreListShow = false;
                            }, 1500)
                        }
                    }

                    //Tab标签计数
                    $('.j_qiangdan span').text(json.Data.GrabOrderTotalCount);
                    $('.j_fanpai span').text(json.Data.TurnOrderTotalCount);

                }, function(obj, e) {
                    if (ifInit) {
                        self.$el.find('.next_page_loading').hide();
                    }
                    if (ifRefresh) {
                        self.$el.find('.pull_loading').hide();
                    }
                    if (ifPull) {
                        loadingNow = false;
                    }
                }, false, isIgnoreLogin)
            },

            renderFanpaiList: function(orderType, tabOpen, isAllDemand, pageIndex, pageSize, ifInit, ifPull, ifRefresh) {
                var self = this,
                    orderType;
                $('.j_isAllDemand').hide();
                $('.j_orderTab').find('a').removeClass('cur');
                $('.j_fanpai').addClass('cur');
                //首次加载时候才显示加载中。。。,详情页回退不显示loading图标
                if (ifInit) {
                    self.$el.find('.next_page_loading').show();
                }
                if (ifRefresh) {
                    self.$el.find('.pull_loading').show();
                }
                if (ifPull) {
                    loadingNow = true;
                }

                var orderListParam = {
                    pageIndex: pageIndex,
                    pageSize: pageSize,
                    orderType: orderType,
                    isAll: isAllDemand
                }

                if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() == 'wechat' || Lizard.P('sourcefrom').toLowerCase() == 'sms')) {
                    $.extend(orderListParam, {
                        platformProviderId: Lizard.P('providerid'),
                        platformUserId: Lizard.P('userid'),
                        orderType: orderType
                    });
                }

                //获取翻牌列表信息
                getOrderListModel.setParam(orderListParam);
                mFacade.excute(self, getOrderListModel, function(json) {
                    var oldListNum = self.$el.find('.goto_rob_detail').length,
                        listTpl;

                    listTpl = fanpaiList;
                    self.$el.find('.list_container').html(_.template(listTpl)({
                        "data": json
                    }));

                    if (window.navigator.userAgent.indexOf('_ctripVBKwireless_android') > 0 || window.navigator.userAgent.indexOf('_CtripWebView_Android') > 0) {
                        window.app.getDeviceInfoCallBack = function(data) {
                            var deviceInfo = JSON.parse(data);

                            self.isNewAppVersion = deviceInfo.version < "1.5.2" ? false : true;
                        };

                        window.VAppUtil.getDeviceInfo();
                        VAppUtil.getDeviceInfo(); //获取app版本
                        if (!self.isNewAppVersion) {
                            $('.j_call').hide();
                        }
                    }

                    //获取IM未读信息条数
                    var userInfo,
                        ctripUid;
                    if (cookieUserInfor || cookieUserInfor != undefined) {
                        userInfo = cookieUserInfor;
                        ctripUid = userInfo.CtripUid || '';
                    } else {
                        ctripUid = "";
                    }

                    var orderListParam = {};
                    $('.goto_rob_detail').forEach(function(ele, i) {
                        var uid = $(ele).attr('data-uid');

                        orderListParam = {
                            "ownerJid": ctripUid,
                            "partnerJid": uid,
                            "type": "chat",
                            "messageBaseLine": 0
                        };

                        GetConversationUnreadInfoModel.setParam(orderListParam);
                        mFacade.excute(self, GetConversationUnreadInfoModel, function(json) {
                            var unreadCount = json.unreadCount,
                                value;


                            if (unreadCount > 0 && unreadCount < 100) {
                                value = unreadCount;
                            } else if (unreadCount == 0) {
                                value = '';
                            } else if (unreadCount > 100) {
                                value = '99+';
                            }
                            $(ele).find('.j_ImChatList i').text(value)

                        }, function(obj, e) {}, false, isIgnoreLogin);

                    });

                    if (ifInit) {
                        self.$el.find('.next_page_loading').hide();
                    }
                    if (ifRefresh) {
                        self.$el.find('.pull_loading').hide();
                    }
                    if (ifPull) {
                        loadingNow = false;
                        listedNum = self.$el.find('.goto_rob_detail').length
                        if (listedNum % 5 != 0 || oldListNum == listedNum) {
                            //防止频繁刷新列表当列表已经拉到底部时设置1500ms的延时才能再度刷新
                            self.$el.find('.rob_list_nomore').show();
                            nomoreListShow = true;
                            setTimeout(function() {
                                self.$el.find('.rob_list_nomore').hide();
                                nomoreListShow = false;
                            }, 1500)
                        }
                    }

                    //Tab标签计数
                    $('.j_qiangdan span').text(json.Data.GrabOrderTotalCount);
                    $('.j_fanpai span').text(json.Data.TurnOrderTotalCount);

                }, function(obj, e) {
                    if (ifInit) {
                        self.$el.find('.next_page_loading').hide();
                    }
                    if (ifRefresh) {
                        self.$el.find('.pull_loading').hide();
                    }
                    if (ifPull) {
                        loadingNow = false;
                    }

                }, false, isIgnoreLogin);
            },

            headFix: function() {
                var self = this;
                if (self.isInApp() && self.isIOS) {
                    // self.$el.find('.view_header').addClass('detail_header_iosapp')
                }
            }
        })

    });